﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hisun.Models;
using Hisun.Controllers;

namespace Hisun.View.ReportQuery
{
    public partial class Report_CPCBBDFXB : AbcPageBase
    {
        HisunDBDataContext db = new HisunDBDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {



                AbcFullAccountPeriod MyFullAp = new AbcFullAccountPeriod();

                MyFullAp.FullAccountPeriodToDropdownlist(DropDownList_Year, DropDownList_Month, Application["accountPeriod"].ToString());
                MyFullAp.FullAccountPeriodToDropdownlist(DropDownList_Year0, DropDownList_Month0, Application["accountPeriod"].ToString());

            }
        }




        protected void Button_Query_Click1(object sender, EventArgs e)
        {
            string MyAccountPeriod1 = DropDownList_Year.SelectedValue.ToString() + DropDownList_Month.SelectedValue.ToString(); ;

            string MyAccountPeriod2 = DropDownList_Year0.SelectedValue.ToString() + DropDownList_Month0.SelectedValue.ToString(); ;
  

            var IsValidString = from a in db.TABC_JS_AccountPeriods
                                where a.会计期间ID == MyAccountPeriod1
                                select a;
            if (IsValidString.Count() == 0)
            {
                Response.Write("<Script>alert('会计期间不存在，请检查输入是否正确')</Script>");
                return;
            }

            var IsValidString1 = from a in db.TABC_JS_AccountPeriods
                                where a.会计期间ID == MyAccountPeriod2
                                select a;
            if (IsValidString1.Count() == 0)
            {
                Response.Write("<Script>alert('比较会计期间不存在，请检查输入是否正确')</Script>");
                return;
            }

            string CurrentUser = Session[ServerVars.sysSessionUserName].ToString();

            CostReport MyReport = new CostReport();
            string myHtmlReport = "";
            myHtmlReport = MyReport.WriteExcel_Report_CPCBBDFXB(MyAccountPeriod1,MyAccountPeriod2, CurrentUser);
            Response.Redirect("/Report/UserReport/" + myHtmlReport + ".html");
        }
    }
}
